package com.example.auth.demo.mapper;

import com.example.auth.demo.domain.auth.Role;
import com.example.auth.demo.domain.auth.Equipment;
import com.example.auth.demo.domain.auth.Task;
import com.example.auth.demo.domain.auth.UserDetail;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import com.example.auth.demo.domain.auth.Player;
import com.example.auth.demo.domain.auth.PlayerFeedback;



import com.example.auth.demo.domain.auth.Guild;
import com.example.auth.demo.domain.auth.GuildActivity;
import com.example.auth.demo.domain.auth.GuildActivityParticipant;
import com.example.auth.demo.domain.auth.GuildChat;
import com.example.auth.demo.domain.auth.GuildContribution;
import com.example.auth.demo.domain.auth.GuildDiplomacy;
import com.example.auth.demo.domain.auth.GuildMember;
import com.example.auth.demo.domain.auth.GuildNotice;


import java.util.List;
import java.util.Map;


@Repository
public interface AuthMapper {


    List<UserDetail> findAllUsers();
    List<UserDetail> findAllUsersByPage(@Param("pageSize") int pageSize, @Param("offset") int offset);
    int countAllUsers();

    /**
     * 根据用户名查找用户
     * @param name
     * @return
     */
    UserDetail findByUsername(@Param("name") String name);

    /**
     * 创建新用户
     * @param userDetail
     */
    void insert(UserDetail userDetail);

    /**
     * 创建用户角色
     * @param userId
     * @param roleId
     * @return
     */
    int insertRole(@Param("userId") long userId, @Param("roleId") long roleId);

    /**
     * 根据角色id查找角色
     * @param roleId
     * @return
     */
    Role findRoleById(@Param("roleId") long roleId);

    /**
     * 根据用户id查找该用户角色
     * @param userId
     * @return
     */
    Role findRoleByUserId(@Param("userId") long userId);

    /**
     * 创建角色
     * @param role
     */
    void insertRoleInfo(Role role);

    /**
     * 修改角色信息
     * @param role
     */
    void updateRoleInfo(Role role);

    /**
     * 删除角色
     * @param roleId
     */
    void deleteRole(@Param("roleId") long roleId);

    /**
     * 获取所有角色
     * @return
     */
    List<Role> getAllRolesByPage(@Param("pageSize") int pageSize, @Param("offset") int offset);
    int countAllRoles();


    /**
     * 添加装备到角色
     * @param roleId 角色ID
     * @param equipmentId 装备ID
     */
    void addEquipmentToRole(@Param("roleId") long roleId, @Param("equipmentId") long equipmentId);

    /**
     * 从角色移除装备
     * @param roleId 角色ID
     * @param equipmentId 装备ID
     */
    void removeEquipmentFromRole(@Param("roleId") long roleId, @Param("equipmentId") long equipmentId);

    /**
     * 获取角色的所有装备
     * @param roleId 角色ID
     * @return 装备列表
     */
    List<Equipment> getRoleEquipments(@Param("roleId") long roleId);

    /**
     * 创建装备
     * @param equipment 装备信息
     */
    void insertEquipment(Equipment equipment);

    /**
     * 根据ID获取装备
     * @param equipmentId 装备ID
     * @return 装备信息
     */
    Equipment getEquipmentById(@Param("equipmentId") long equipmentId);


    // 获取所有装备列表
    List<Equipment> getAllEquipmentsByPage(@Param("pageSize") int pageSize, @Param("offset") int offset);
    int countAllEquipments();

    // 更新装备信息
    void updateEquipment(Equipment equipment);

    /**
     * 创建任务
     * @param task 任务信息
     */
    void insertTask(Task task);

    /**
     * 为角色分配任务
     * @param roleId 角色 ID
     * @param taskId 任务 ID
     */
    void assignTaskToRole(@Param("roleId") long roleId, @Param("taskId") long taskId);

    /**
     * 标记角色的任务为已完成
     * @param roleId 角色 ID
     * @param taskId 任务 ID
     */
    void markTaskAsCompleted(@Param("roleId") long roleId, @Param("taskId") long taskId);

    /**
     * 获取角色的所有任务
     * @param roleId 角色 ID
     * @return 任务列表
     */
    List<Task> getRoleTasks(@Param("roleId") long roleId);

    /**
     * 获取角色未完成的任务
     * @param roleId 角色 ID
     * @return 未完成任务列表
     */
    List<Task> getIncompleteRoleTasks(@Param("roleId") long roleId);

    /**
     * 获取角色已完成的任务
     * @param roleId 角色 ID
     * @return 已完成任务列表
     */
    List<Task> getCompletedRoleTasks(@Param("roleId") long roleId);

    /**
     * 根据 ID 获取任务
     * @param taskId 任务 ID
     * @return 任务信息
     */
    Task getTaskById(@Param("taskId") long taskId);
    List<Task> getAllTasksByPage(@Param("pageSize") int pageSize, @Param("offset") int offset);

    /**
     * 统计所有任务数量（新增方法）
     * @return 任务总数
     */
    int countAllTasks();

    List<Task> getIncompleteTasksByUserId(Long userId);
    List<Task> getCompletedTasksByUserId(Long userId);


    void insertPlayer(Player player);

    Player getPlayerByAccount(@Param("account") String account);

    Player getPlayerById(@Param("playerId") Long playerId);

    void updatePlayer(Player player);

    void insertPlayerFeedback(PlayerFeedback feedback);

    List<PlayerFeedback> getPlayerFeedbacks(@Param("playerId") Long playerId);

    // 分页查询未处理反馈
    List<PlayerFeedback> getUnprocessedFeedbacksByPage(Map<String, Object> params);

    // 统计未处理反馈总数
    int countUnprocessedFeedbacks();

    void markFeedbackAsProcessed(@Param("feedbackId") Long feedbackId);



    List<Player> getPlayerListByPage(Map<String, Object> params);
    int countPlayerList(Map<String, Object> params);
    void deletePlayer(Long id);



    // 公会表相关
    void insertGuild(Guild guild);
    Guild getGuildById(@Param("guildId") Long guildId);
    List<Guild> getAllGuilds();
    void updateGuild(Guild guild);
    void deleteGuild(@Param("guildId") Long guildId);

    List<Guild> getGuildsByPage(
            @Param("offset") int offset,
            @Param("pageSize") int pageSize,
            @Param("sortField") String sortField,
            @Param("sortOrder") String sortOrder
    );
    int countAllGuilds();

    // 公会成员表相关
    void insertGuildMember(GuildMember member);
    GuildMember getGuildMemberById(@Param("memberId") Long memberId);
    List<GuildMember> getGuildMembersByGuildId(@Param("guildId") Long guildId);
    void updateGuildMember(GuildMember member);
    void deleteGuildMember(@Param("memberId") Long memberId);
    List<GuildMember> getAllGuildMembers(int offset, int pageSize);
    int countAllGuildMembers();

    // 公会公告表相关
    void insertGuildNotice(GuildNotice notice);
    GuildNotice getGuildNoticeById(@Param("noticeId") Long noticeId);
    List<GuildNotice> getGuildNoticesByGuildId(@Param("guildId") Long guildId);
    void updateGuildNotice(GuildNotice notice);
    void deleteGuildNotice(@Param("noticeId") Long noticeId);

    List<GuildNotice> getAllGuildNotices(int offset, int pageSize);
    int countAllGuildNotices();

    // 公会活动表相关
    void insertGuildActivity(GuildActivity activity);
    GuildActivity getGuildActivityById(@Param("activityId") Long activityId);
    List<GuildActivity> getGuildActivitiesByGuildId(@Param("guildId") Long guildId);
    void updateGuildActivity(GuildActivity activity);
    void deleteGuildActivity(@Param("activityId") Long activityId);

    List<GuildActivity> getAllGuildActivities(int offset, int pageSize);
    int countAllGuildActivities();
    // 公会活动参与表相关
    void insertGuildActivityParticipant(GuildActivityParticipant participant);
    List<GuildActivityParticipant> getParticipantsByActivityId(@Param("activityId") Long activityId);
    void deleteGuildActivityParticipant(@Param("participantId") Long participantId);
    List<GuildActivityParticipant> getAllActivityParticipants();
    // 公会贡献表相关
    void insertGuildContribution(GuildContribution contribution);
    List<GuildContribution> getContributionsByPlayerId(@Param("playerId") Long playerId);
    List<GuildContribution> getContributionsByGuildId(@Param("guildId") Long guildId);
    void updateGuildContribution(GuildContribution contribution);

    List<GuildContribution> getAllGuildContributions(@Param("offset") int offset, @Param("pageSize") int pageSize, @Param("orderBy") String orderBy);
    int countAllGuildContributions();
    // 公会外交关系表相关
    void insertGuildDiplomacy(GuildDiplomacy diplomacy);
    GuildDiplomacy getGuildDiplomacyById(@Param("diplomacyId") Long diplomacyId);
    List<GuildDiplomacy> getDiplomaciesByGuildId(@Param("guildId") Long guildId);
    void updateGuildDiplomacy(GuildDiplomacy diplomacy);
    void deleteGuildDiplomacy(@Param("diplomacyId") Long diplomacyId);

    // 添加带分页和排序的查询方法
    List<GuildDiplomacy> getAllDiplomaciesByPage(
            @Param("offset") int offset,
            @Param("pageSize") int pageSize,
            @Param("orderBy") String orderBy
    );

    // 添加统计总记录数的方法
    int countAllDiplomacies();
    // 公会聊天表相关
    void insertGuildChat(GuildChat chat);
    List<GuildChat> getChatsByGuildId(@Param("guildId") Long guildId);
}
